<template>
  <div class="content-boss" ref="citys">
    <div>
      <h2>当前城市</h2>
      <div class="content-nowCity">
        <div class="content-nowCity-text">
          {{$store.state.changs}}
        </div>
      </div>
      <h2>热门城市</h2>
      <div class="content-popularCity">
        <ul>
            <li v-for="item of list" :key="item.id" @click="selectCity(item.name)">
              <div class="popularCity-text">{{item.name}}</div>
            </li>
        </ul>
      </div>
      <div class="content-a" v-for="(value,key) of contList" :key="key">
        <h2 :ref="key">{{key}}</h2>
        <ul>
          <li class="content-a-list border-bottom" v-for="items of value" :key="items.id" @click="selectCity(items.name)">{{items.name}}</li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import BScroll from 'better-scroll'
export default {
  name: 'CityContent',
  props: {
    list: Array,
    contList: Object,
    letter: String
  },
  data () {
    return {
    }
  },
  methods: {
    selectCity (city) {
      this.$router.push('/')
      this.$store.dispatch('changCity', city)
    }
  },
  mounted () {
    this.scroll = new BScroll(this.$refs.citys, {
      tap: true,
      click: true
    })
  },
  watch: {
    letter () {
      this.scroll.scrollToElement(this.$refs[this.letter][0], 300)
    }
  }
}
</script>

<style lang="stylus" scoped="scoped">
  .content-boss
    position absolute
    top 1.98rem
    left 0
    right 0
    bottom 0
    z-index -1
    overflow hidden
  .content-boss>>>div
    overflow hidden
    h2
      background #f5f5f5
      padding 0.13rem 0
      padding-left 0.2rem
    .content-nowCity-text
      border 0.02rem solid #CACACA
      width 2.3rem
      margin 0.2rem 0 0.2rem 0.2rem
      text-align center
      padding 0.11rem 0
      border-radius 0.06rem
    .content-popularCity
      li
        float left
      .popularCity-text
        border 0.02rem solid #CACACA
        width 2.3rem
        margin 0.2rem 0 0.2rem 0.2rem
        text-align center
        padding 0.11rem 0
        border-radius 0.06rem
    .content-a
      clear both
    .content-a-list
      padding 0.3rem 0 0.4rem 0.2rem
</style>
